#! 
# by jzhang @ 09:15 2004-03-29  mailto:jzhang533@263.net
#

use File::Basename;

@ARGV == 1 or die "Usage:\n\t".basename($0)." dirname\n";

sub EnumDir
{
    my $dirname = $_[0];
    my $depth = 0;
    $depth = $_[1] if(@_ == 2);  

    opendir (MYDIR,$dirname) or die"can not open $dirname:$!";
    my @list = grep(!/^(\.)|(\..)$/,readdir MYDIR);

    my @files = grep {-f $dirname."/$_"} @list;
    my @dirs = grep {-d $dirname."/$_"} @list;
    
    foreach (@files)
    {
            print "|" if( $depth>=1);
            print "   " for(1..$depth-1);
            print "|$_\n";
    }
    foreach(@dirs)
    {
        if($depth == 0)
        {
            print "+";
        }
        else
        {
            print "|";
        }
        print "   " for(1..$depth);
        if($depth == 0)
        {
            print "---";
        }
        else
        {
            print "+";
        }        
        print $_."\n";
        EnumDir ($dirname."/$_",$depth+1);
    }
}

print $ARGV[0]."\n";
EnumDir $ARGV[0];
